package com.synergy.stockflow.entity.dto;

import com.synergy.stockflow.entity.SysUser;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Schema(description = "用户数据传输对象 - 用于新增/更新")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SysUserDTO {
    private String tenantId;

    @Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED)
    private String username;

    @Schema(description = "昵称")
    private String nickname;

    @Schema(description = "邮箱")
    private String email;

    @Schema(description = "手机号")
    private String phone;

    @Schema(description = "性别: 0-男, 1-女, 2-保密")
    private Byte gender = 2;

    @Schema(description = "部门编号")
    private Integer deptId;

    private Byte status = 1;

    @Schema(description = "角色分配")
    private List<String> roleCodes;

    public static SysUser toEntity(SysUserDTO dto) {
        if (dto == null) return null;
        SysUser user = new SysUser();
        user.setUsername(dto.getUsername());
        user.setNickname(dto.getNickname());
        user.setEmail(dto.getEmail());
        user.setPhone(dto.getPhone());
        user.setGender(dto.getGender() != null ? dto.getGender() : 2);
        user.setStatus(dto.getStatus() != null ? dto.getStatus() : 1);
        user.setDeptId(dto.getDeptId());
        user.setTenantId(dto.getTenantId());
        return user;
    }
}